package com.cars.shardingspheredemo.controller;

import com.cars.shardingspheredemo.entities.Course;
import com.cars.shardingspheredemo.service.CourseService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/course")
public class CourseController {

    @Resource
    private CourseService courseService;

    @GetMapping("/{id}")
    public Course getById(@PathVariable String id) {
        return this.courseService.getById(id);
    }

    @GetMapping("")
    public List<Course> list() {
        return this.courseService.list();
    }

    @GetMapping("/count")
    public Long count() {
        return this.courseService.count();
    }

    @GetMapping("/mock")
    public String mock() {
        for (int i = 0; i < 12; i++) {
            final Course course = new Course();
            final Long index = (long) (i + 1);
            course.setCid(index);
            course.setCname("语文课");
            course.setUserId(123456L);
            course.setCstatus("valid");
            this.courseService.save(course);
        }
        return "SUCCESS";
    }

}